﻿using System.Net.Http;
using System.Net.Http.Headers;
using Flurl;
using Newtonsoft.Json;
using ZilLion.Core.Unities.UnitiesMethods;
using ZilLion.TaskManager.Entity.Config;
using ZilLion.TaskManager.Entity.Entity;
using ZilLion.TaskManager.Entity.Response;

namespace ZilLion.TaskManager.Repository
{
    public class TaskCommandRespository : ITaskCommandRespository
    {
        public TaskCommandResponse GetUnHandleTaskConmmandEntities(string nodeid)
        {
            var url = Url.Combine(TaskManagerGlobalSetting.GetInstance().ManagerServiceHost,
                "Api", "TaskPlatform",
                "TaskCommand", "UnHandleConmmand"
            );
          
            return HttpHelper.HttpRequestGet<TaskCommandResponse>($"{url}?nodeid={nodeid} ");
        }

        public bool SaveTaskConmmandEntity(TaskConmmandEntity entity)
        {
            var url = Url.Combine(TaskManagerGlobalSetting.GetInstance().ManagerServiceHost, "Api",
                "TaskPlatform",
                "TaskCommand", "SaveTaskConmmand"
            );


            var httpcontent = new StringContent(JsonConvert.SerializeObject(entity))
            {
                Headers = {ContentType = new MediaTypeHeaderValue("application/json")}
            };


            var response = HttpHelper.HttpRequestPost<ResponseBase>($"{url} ", httpcontent);
            return response != null && response.IsSuccess;
        }
    }
}